package com.webemail.sys.service.impl;

import java.util.List;

import javax.annotation.Resource;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson2.JSON;
import com.webemail.sys.mapper.SysLabelMessageMapper;
import com.webemail.sys.model.SysLabelMessage;
import com.webemail.sys.service.LabelMessageService;

/**
 * @author LaiHQ
 */
@Service
public class LabelMessageServiceImpl extends ServiceImpl<SysLabelMessageMapper,SysLabelMessage> implements LabelMessageService {
	private Logger logger = LoggerFactory.getLogger(getClass());

	@Resource
	public SysLabelMessageMapper sysLabelMessageMapper;

	@Override
	public int insert(SysLabelMessage temp) {
		// TODO Auto-generated method stub
		logger.info("class:" + this.getClass().getName() + " method:" + "insert" + " param:" + JSON.toJSONString(temp));
		return sysLabelMessageMapper.insert(temp);
	}

	@Override
	public int delete(long id, long userId) {
		// TODO Auto-generated method stub
		logger.info("class:" + this.getClass().getName() + " method:" + "delete" + " param:" + "id:" + id + "userId:"
				+ userId);
		SysLabelMessage temp = new SysLabelMessage();
		temp.setId(id);
		temp.setUserId(userId);
		return sysLabelMessageMapper.deleteById(temp);
	}

	@Override
	public int update(SysLabelMessage temp) {
		// TODO Auto-generated method stub
		logger.info("class:" + this.getClass().getName() + " method:" + "update" + " param:" + JSON.toJSONString(temp));
		return sysLabelMessageMapper.updateById(temp);
	}

	@Override
	public SysLabelMessage get(long id, long userId) {
		logger.info("class:" + this.getClass().getName() + " method:" + "get" + " param:" + "id:" + id + "userId:"
				+ userId);
		return sysLabelMessageMapper.selectOne(Wrappers.lambdaQuery(SysLabelMessage.class)
				.eq(SysLabelMessage::getId,id)
				.eq(SysLabelMessage::getUserId,userId));
	}

	@Override
	public List<SysLabelMessage> list(long userId, String labelId) {
		logger.info("class:" + this.getClass().getName() + " method:" + "list" + " param:" + "labelId:" + labelId
				+ "userId:" + userId);
		return sysLabelMessageMapper.selectList(Wrappers.lambdaQuery(SysLabelMessage.class)
				.eq(SysLabelMessage::getLabelId,labelId)
				.eq(SysLabelMessage::getUserId,userId));
	}

	@Override
	public int insert(List<SysLabelMessage> temp) {
		logger.info("class:" + this.getClass().getName() + " method:" + "insert" + " param:" + JSON.toJSONString(temp));
		this.saveBatch(temp);
		return temp.size();
	}

	@Override
	public int deleteBath(long userId, String labelId) {
		// TODO Auto-generated method stub
		logger.info("class:" + this.getClass().getName() + " method:" + "deleteBath" + " param:" + "labelId:" + labelId
				+ "userId:" + userId);
		SysLabelMessage temp = new SysLabelMessage();
		temp.setLabelId(labelId);
		temp.setUserId(userId);
		return sysLabelMessageMapper.delete(Wrappers.lambdaQuery(SysLabelMessage.class)
				.eq(SysLabelMessage::getLabelId,labelId)
				.eq(SysLabelMessage::getUserId,userId));
	}

	@Override
	public SysLabelMessage get(long userId, String labelId, String messageId, String table) {
		// TODO Auto-generated method stub
		SysLabelMessage temp = new SysLabelMessage();
		temp.setLabelId(labelId);
		temp.setUserId(userId);
		temp.setMessageId(messageId);
		temp.setTable(table);
		return sysLabelMessageMapper.selectOne(Wrappers.lambdaQuery(SysLabelMessage.class)
				.eq(SysLabelMessage::getLabelId,labelId)
				.eq(SysLabelMessage::getUserId,userId)
				.eq(SysLabelMessage::getMessageId,messageId)
				.eq(SysLabelMessage::getTable,table));
	}

}
